package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mall.dubbo.mappers.PmsSkuStockMapper;
import com.tanhua.model.domain.PmsSkuStock;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@DubboService
public class PmsSkuStockApiImpl implements PmsSkuStockApi{
    @Autowired
    private PmsSkuStockMapper pmsSkuStockMapper;


    /**
     * 根据商品ID及sku编码模糊搜索sku库存
     * @param pid
     * @param keyword
     * @return
     */
    @Override
    public List<PmsSkuStock> findByPid(Long pid, String keyword) {
        LambdaQueryWrapper<PmsSkuStock> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(pid != null,PmsSkuStock::getProductId,pid)
                .like(keyword != null,PmsSkuStock::getSkuCode,keyword);

        return pmsSkuStockMapper.selectList(lambdaQueryWrapper);
    }


    /**
     * 批量更新sku库存信息
     * @param pid
     * @param skuStockList
     * @return
     */
    @Override
    public void updateByPid(Long pid, List<PmsSkuStock> skuStockList) {
        for (PmsSkuStock pmsSkuStock : skuStockList) {
            pmsSkuStockMapper.updateById(pmsSkuStock);
        }
    }
}
